<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="author" content="zhaozhenguo">
		<title>礼品领奖出库单</title>
		<!--js库及样式-->
		<script LANGUAGE="javascript" src="../script/common.js" type="text/javascript"></script>
		<!--动态js-->
		<script language="javascript" type="text/javascript">
			//全局变量
			var org = Common.cOrg();	//当前单位
			var oper=Common.cOperator();
			var qt = {};				//数据表格对象
			var qtx= {};
			var qt3 = {};
			var qtmx = {};
			var orderid;//GiftOrder
			var orderCode;
		     var giftid;
		     var typelist=[{code:"1",text:"现场预约"},{code:"2",text:"在线预约"}]
			//页面加载方法
			function load(){
			   Common.initDict(inventoryorder.caltype,typelist);
			   $("listform").organization1.value=org.id;
			    $("inventoryorder").organization.value=org.id;
				Eui.showNavigation();	
				setPages(["listview","itemlists","insertview","updateview","newinventoryorder","showlistdiv","printview"]);
				createTable();	
				//createTablex();
			}
			function createTable(){
				var columns = [];
				columns[4]={title:"操作",width:"20%",render:showItems,order:false}
				/*var columns = [	
					{type:"checkbox"},
					{title:"礼品领奖出库单号",width:"20%"},
					{title:"参考外部单据号",width:"20%"},
					{title:"礼品管理员",width:"20%"},
					{title:"出库时间",width:"20%",render:function(v){return v?v.format():""}},
					{title:"操作",width:"20%",render:showItems,order:false}
				]*/
				qt = new QueryTable("loy_gift_give_query_bill","listform","datalist",columns,{
					buttons:[
						{value:"增 加",actions:onNewOrder},
					]
				});
			}
			function outStore(v,r){
				 return "<a href=# onclick=\"showlists('"+r[0]+"','"+r[2]+"','"+r[3]+"','"+r[4]+"',"+r[5]+",'"+r[6]+"','"+r[7]+"','"+r[8]+"');return false;\">查看要出库明细</a>"
			}
			function showlists(code,state,name,plantime,vplantime,points,oper,id){
		          $("vorderid").innerHTML=code;
		          if(name==null){
		           $("usernames").innerHTML=""; 
		          } 
		            
		           $("usernames").innerHTML=name; 
	                $("plantime").innerHTML=plantime;
	                $("point").innerHTML=points;
	                $("oper").innerHTML=oper;
	      
                  $("listform2").bookordid.value=id;
                     orderid=id;
			      createTable3();
			      showData3();
	                switchPage("showlistdiv");  	
		      
		          
		}
		function showData3(){	
			qt3.showTable();				//qt1为全局的QueryTable对象
		}
	     function createTable3(){
		var columns =[];
		qt3= new QueryTable("createTable3_2_query","listform2","showlist",columns,{showData:"true",
					buttons:[
						{value:"出库",actions:outOrder},
						{value:"返 回",actions:resetF}
					]
				});	
		}
		function outOrder(){
		        DWR.call('giftStorageService.addBookOrderToInventoryOrder',orderid,function(v){
		         giftid=v.id;
		         requestframe.document.location.href = "print_emerge_gift.html";
			  	 switchPage("printview");  
			    });
		}
		function resetF(){
		    switchPage("newinventoryorder");  	
		}
		function createTablex(){
	      	   var columns =[];
			   columns[6]={title:"操作",width:"15%",render:outStore}
			/*var columns = [
				{title:"订单编号",width:"13%"},																
				{title:"客户姓名",width:"13%"},															
				{title:"申请时间",width:"13%",render:function(v){return v?v.format():""}},	
				{title:"预约时间",width:"13%",render:function(v){return v?v.format():""}},																
				{title:"所用积分",width:"13%"},											
				{title:"操作员",width:"12%"},
				{title:"查看",width:"12%",render:showlist}										
			]*/

			
       qtx = new QueryTable("createTable1_2_query","inventoryorder","datalist1",columns,{
					buttons:[
						{value:"返 回",actions:resetFunc}
					]
				});
					
		}
			function itemCreateTable(){
				var columns =[];
				/*var columns = [
					{type:"checkbox"},		//复选框
					{title:"商品类型",width:"15%"},	
					{title:"商品子类型",width:"15%"},	                      //点击进入修改
					{title:"商品名称",width:"15%"},						
					{title:"出库数量",width:"10%"},					
					{title:"计量单位",width:"10%"},
					{title:"备注",width:"20%"},
					{title:"操作",width:"15%",render:updateItem,order:false}
				]*/
				qtmx = new QueryTable("loy_gift_give_query_item","","itemlist",columns,{showData:"true",
					buttons:[
						{value:"返 回",actions:resetFunc}
					]
				});
			
				qtmx.paramFunc = function(){
					var params = {};
					params.giftOrderCode = orderCode;
					return params;
				}
			}
			function showData(){
				qt.showTable();
			}
		     function showDatax(){
                qtx.showTable();
		     }
		      function showDataItemList(){
                qtmx.showTable();
		     }
			function showItems(v,r){
				return "<a href=# onclick=\"showItems2("+r[0]+",'"+r[1]+"','"+r[2]+"','"+r[3]+"');return false;\">查看</a>"
			}
			var codeids;
			var codeids2;
			var dates;
			function showItems2(codeid,codeid2,oper,date){
		        
				     orderCode =codeid;
					$("orderCode").innerHTML=codeid;
					$("refCode").innerHTML=codeid2;
			          $("operator").innerHTML=oper;
			          $("checkDateTime").innerHTML=date;  
					itemCreateTable();
					//showDataItemList();
					switchPage("itemlists");
			
			}
			//显示新增界面
			function update2(){
			if(!checkForm(updateform))return;
			    var id=updateform.id.value;
			    var qu=updateform.quantity.value;
			    var comments=updateform.comments.value;
				DWR.call('giftStorageService.updateOutInventoryItem',id,qu,comments,function(v){
				    itemCreateTable(); 
				    if(v){
				    	showError("你输入的数量不能大于库存数量");
				    }
			    });
				switchPage('itemlists');	
			}
			function onNewOrder(){
			     createTablex();
				switchPage("newinventoryorder");
			}
			//选择单位控件
			function selOrg(){			
				var v = openDialogFrame("/client/loy_giftinventory_list.html",'选择商品',500,600)
				if (v){		
	                $("insertform").giftName.value = v.name;
				    giftid=v.id;
				}
			}
			function selOrg2(){			
				var v = openDialogFrame("/client/loy_giftinventory_list.html",'选择商品',500,600)
				if (v){		
	            	$("caigoumxxz").giftName.value = v.name;
				    giftid=v.id;
				}
			}
			//取消方法
			function resetFunc(){
				switchPage('listview');
			    showData();
			}
			//保存方法
			function onSaveOrAddOrder(){
			    if(!checkForm("inventoryorder"))return;
			    var inventoryorder1 = Common.getValues("inventoryorder");
				if (!inventoryorder1.id)
				inventoryorder1.operator=oper.id;
				inventoryorder1.flag=1;
				inventoryorder1.giftLocation=org.id;      
				DWR.call('giftStorageService.createInventoryOrder',inventoryorder1,Constants.GIFT_INVENTORY_IN_GIVE,function(v){
					switchPage('insertview');
				    getOrderId(v.id,v.orderCode,v.refCode,v.checkDateTime);       
			    });
			    function getOrderId(id,orderCode,refCode,checkDateTime){
					var datetime=new Date(checkDateTime);
				    orderid=id;
				    codeids=orderCode;
		            codeids2=refCode;
		            dates=datetime.format();    
			    }		 
			}
			function back(){
			  createTablex();
		      showDatax();
              switchPage("newinventoryorder");  
			}
			function onSaveOrAddItem(){
			
				if(!checkForm(insertform))return;
		        var inventoryitem = Common.getValues(insertform);
			    if (!inventoryitem.id)
			    inventoryitem.inventoryOrder=orderid;
			    inventoryitem.gift=giftid;      
				DWR.call('giftStorageService.addOutInventoryItem',inventoryitem,function(v){
					if(v==1){
						showInformation("添加失败，已有此商品了");
					}else if(v==2){
						showInformation("库存不足");
					}else{
						showInformation("添加成功!");
					}	         
				});
				insertform.reset();
			}
			function qx(){
				switchPage('selectdetview');
			}
			function xzFunc(){
				$("caigoumxxz").reset();
				switchPage('detviewmxxz');
			}
			function resetItem(){
		    	insertform.reset();
			}
			function resetItem2(){
		    	insertform.reset();
			}
			//删除方法

			
	        function onBackItemList(){ 
	        	itemCreateTable();
				if(codeids!=null){
					$("orderCode").innerHTML=codeids;
				 	$("refCode").innerHTML=codeids2;
		        	$("operator").innerHTML=oper.name;
		        	$("checkDateTime").innerHTML=dates;
				}
	        	switchPage('itemlists');
	        }
			function onCancl1(){
				switchPage('listview');
			}
			function onCancl2(){
				switchPage('itemlists');
			}
		
		</script>
	</HEAD>
	<body onload="load()">
		<!--页面导航-->
		<div class="nav"><div id="nav">&nbsp;</div></div>
		<div id="listview">	
			<div class="searchForm">
				<form id="listform" name="listform">
					<input type="hidden" id=organization1 name="organization1">
					<table cellSpacing=0 cellPadding=4 width="100%" border=0 >
					    <tr>
						    <td><label>领奖出库单号</label> <input type="text" name="instoCode" maxlength=15></td>
						    <td><label>领奖出库日期</label> <input type="text" name="instoDate" onblur="checkV(this,'date')"><a href="javascript:void(0)" onclick='showDatePicker( $("instoDate"));' class="date" title="选择日期">&nbsp;&nbsp;</a></td>
							<td><button type="button" onclick="showData()">查 询</button></td>
						</tr>
					</table>
				</form>	
			</div>
			<div id="datalist"></div>	
		</div>
		<div class="printview" id="printview" style='display:none;'>
			<iframe id="requestframe" name="requestframe" style="width:100%;height:90%;overflow:auto;" frameborder=0 src=""></iframe>
		</div>
		<div id="itemlists" style="display:none;">
			<div class="form">
				<form id="listform1" name="listform1">
					<input type="hidden" id=giftOrderCode name=giftOrderCode/>
					<div class="formTitle">礼品领奖出库单详细信息</div>
					<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="viewTable">
						<tr>
							<td><label>领奖出库单号</label> <span id="orderCode"></span></td>
							<td><label>参考外部单据号</label> <span id="refCode"></span></td>
						</tr>
						<tr>		
							<td><label>领奖出库日期</label> <span id="checkDateTime"></span></td>
						    <td><label>操&nbsp;&nbsp;&nbsp;作&nbsp;&nbsp;&nbsp;员&nbsp;&nbsp;</label> <span id="operator"></span></td>
						</tr>
					</table>		 
				</form>
			</div>
			<div id="itemlist"></div>
		</div>
		<!--明细(新增)静态页面部分-->
		
		
		     <div id="newinventoryorder" style="display:none;">
				<form id="inventoryorder" name="inventoryorder">
				  <input type="hidden" id=organization name="organization">
					<table cellSpacing=0 cellPadding=4 width="100%" border=0>	
							<tr>
					          <td width=50%><label for="orderCode">兑奖单编号</label> <input type="text" name='orderCode' id='orderCode'></td>
					         <td width=30%>客户姓名<input type=text name="loginName1" id="loginName1"></td>
					         </tr>
					          <tr>
					              <td width=30%>预定类型 &nbsp;&nbsp;<select name="caltype" readonly onblur="checkV(this,'',true)"/></td>
					         <td width=30%><label for=reqDateTime>申请日期</label> <input type=text name="reqDateTime" id="reqDateTime" onblur="checkV(this,'date')> <a href="javascript:void(0)" onclick='showDatePicker( $("reqDateTime"));' class="date" title="选择日期">&nbsp;&nbsp;</a></td>	
						     <td>	<button type="button" onclick="showDatax()">查 询</button></td>
					         </tr>	
					</table>
				</form>
			
			<div class=listBorder>
			    <div class="listBar">
				<div class="listTitle">礼品兑奖单列表</div>
				<div class="listBtn" id="listBtn">
				</div>
			</div>
			<div id=datalist1></div>
		</div>	

		</div>
	<div id="showlistdiv" style='display:none;'>
		<form id='listform2' name='listform2'>
		   <input type=hidden id=bookordid name=bookordid>
			<div class=form>
				<div class="formTitle">兑奖信息</div>
				<table cellSpacing=0 cellPadding=4 width="100%" border=0 class="viewTable">
					 <tr>
					    <td><label >兑奖单编号</label> <span name='vorderid' id='vorderid'></span></td>
					    <td><label>客户姓名</label> <span name="usernames" id="usernames"></span></td>	
					</tr>
					<tr>		
						<td><label>申请日期</label> <span name='plantime' id='plantime'></span></td>
					    <td><label>所用积分</label> <span name='point' id='point'></span></td>						
					</tr>	
					<tr>
						<td><label>操 作 员</label> <span name='oper' id='oper'></span></td>
					</tr>	
				</table>
			</div>	 
		</form>
		<div class=listBard>
			<div class="listBar">
				<div class="listTitles">所兑礼品信息</div>	
			</div>

<div id=showlist></div>
</div>	
	   </div>
	
	</body>
</HTML>